// -*- c-basic-offset: 2 default-tab-width: 2 indent-tabs-mode: t -*-
// vim: autoindent tabstop=2 noexpandtab shiftwidth=2 softtabstop=2
#include "Any.h"
#include "Array.h"

#include "util.h"


namespace R {
	//namespace {
		static void dispatchError(Any *x, Any *y){
			rfatal("No valid dispatch for column operator");
		}

		template <typename RT, typename L, typename R>
			RT* columnOperatorImpl(L *l, R *r){
				R_PARAM(l);
				R_PARAM(r);
				R_VAR(RT*, res);

				// FIXME check size is not 0
				TYPE(L) from = l->getElement(0);
				TYPE(R) to = r->getElement(0);
				// FIXME warn if size is > 1

				if(from > to){
					int len = from - to;
					res = RT::doNew(len + 1);
					int i = len + 1;
					TYPE(L) val = from - len;
					for(; i; val ++)
						res->setElement(val, --i);
				} else {
					int len = to - from;
					res = RT::doNew(len + 1);
					int i = len + 1;
					TYPE(L) val = from + len;
					for(; i ; val --)
						res->setElement(val, --i);
				}
				return res;
			}
		#include "Sequence.inc"
	//}
}

